package gemini.castor.ui.client.page.navigation;

import gemini.castor.ui.client.utils.PlaceConstants.NavigationItem;

import com.google.gwt.event.shared.GwtEvent;

public class NavigationEvent extends GwtEvent<NavigationHandler> {
	
	private static Type<NavigationHandler> TYPE;
	private NavigationItem item;

	public static Type<NavigationHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<NavigationHandler>();
		return TYPE;
	}
	
	public enum ForwardType {
		CLICK, SELECTED;
	}
	
	private ForwardType forwardType;

	public ForwardType getForwardType() {
		return forwardType;
	}

	public void setForwardType(ForwardType forwardType) {
		this.forwardType = forwardType;
	}

	public NavigationEvent(NavigationItem item){
		this.item = item;
		this.setForwardType(ForwardType.CLICK);
	}
	
	@Override
	protected void dispatch(NavigationHandler handler) {
		if (forwardType.equals(ForwardType.CLICK)) {
			handler.onClick(this);
		} else {
			handler.onSelected(this);
		}
	}

	@Override
	public Type<NavigationHandler> getAssociatedType() {
		return getType();
	}

	public NavigationItem getItem() {
		return item;
	}
}
